/**********************总搜索节点************************/
let search_total = function () {
    this.searchInput = document.querySelector(".searchInput");
    this.searchFrame = document.querySelector(".searchFrame");
    this.inputText = document.querySelectorAll(".input-value");
    this.searchFrameSpan = document.querySelectorAll(".searchFrame-node-span");
    this.kind = document.querySelectorAll(".kind-content");
    this.lineSelect = document.querySelector(".line-select");
};

//调整输入下拉框的大小
search_total.prototype.getAdjust = function () {
    this.searchFrame.style.width = this.searchInput.clientWidth + "px";
};

//输入的值
search_total.prototype.inputValue = function () {
    let that = this;
    that.searchInput.oninput = function () {
        for (let i = 0; i < that.inputText.length; i++) {
            that.inputText[i].innerText = that.searchInput.value;
            that.searchFrame.style.display = "block";
            if (i < 2) {
                that.searchFrameSpan[i].style.display = "inline-block";
            }
            if (that.searchInput.value === "") {
                for (let i = 0; i < 2; i++) {
                    that.searchFrameSpan[i].style.display = "none";
                    that.searchFrame.style.display = "none";
                }
            }
        }
    }
};

//选中类似
search_total.prototype.selectKind = function () {
    let that = this;
    for (let i = 0; i < this.kind.length; i++) {
        that.kind[i].onclick = function () {
            for (let i = 0; i < that.kind.length; i++) {
                if (that.kind[i] === this) {
                    that.lineSelect.style.left = i * 82 + "px";
                }
            }
        }
    }
};

//设置下面分享还是用户选择栏的长度
search_total.prototype.setWidthOfSelectKind = function () {
    let that = this;
    if (document.querySelectorAll(".kind")[0])
        document.querySelectorAll(".kind")[0].style.width = that.kind.length * 82 + "px";
};
search_total.prototype.init = function () {
    this.setWidthOfSelectKind();
    this.getAdjust();
    this.inputValue();
    this.selectKind();
};
let searchAll = new search_total();
searchAll.init();
tool.on(window, 'resize', function () {
    searchAll.getAdjust();
});

/********************图片轮播模态框*****************/
let ScrollPhotoComponent = function (arrayNode) {
    this.timerOne = null;
    this.appendNode = null;
    this.pareNode = arrayNode.pareNode;
    this.pointNode = arrayNode.pointNode;
    this.pointLeft = arrayNode.pointLeft;
    this.pointRight = arrayNode.pointRight;
};
ScrollPhotoComponent.prototype.setPlayLeftAndRight = function () {
    this.pointLeft.style.display = "none";
    this.pointRight.style.display = "none";
    let that = this;
    this.pareNode.onmouseover = function () {
        that.pointLeft.style.display = "block";
        that.pointRight.style.display = "block";
    };
    this.pareNode.onmouseout = function () {
        that.pointLeft.style.display = "none";
        that.pointRight.style.display = "none";
    }
};
//设置data
ScrollPhotoComponent.prototype.setData = function (data) {
    if (data) {
        return data;
    }
    return search_test.obj;
};
/*//单个节点
ScrollPhotoComponent.prototype.oneNode = function (data) {
    return '<div class="searchPerson-item item">\n' +
        '<div class="searchPerson-item-img"><img src="' + data.userLogo.thumbUrl+ '"></div>\n' +
        '<a class="searchPerson-item-name">' + data.userName + '</a>\n' +
        '</div>';
};*/
ScrollPhotoComponent.prototype.setOnePhotoNode = function (func) {
    if (func) {
        this.appendNode = func;
    } else {
        throw new error("未传递函数");
    }
};
//打印所有节点
ScrollPhotoComponent.prototype.addAllNode = function (data) {
    let arr = this.setData(data),
        div;
    for (let i = 0; i < arr.length; i++) {
        div = this.appendNode(arr[i]);
        this.pointNode.innerHTML += div;
    }
};
//适应长度
ScrollPhotoComponent.prototype.adjustWidth = function (length, data) {
    let arr = this.setData(data);
    this.pointNode.style.width = arr.length * length + "px";
    this.pointNode.style.left = "0px";
    for (let i = 0; i < this.pointNode.querySelectorAll(".item").length; i++) {
        this.pointNode.querySelectorAll(".item")[i].style.width = length - 6 + "px";
    }
};
//适应屏幕
ScrollPhotoComponent.prototype.resizeToWindow = function (flag) {
    let that = this,
        flagToScroll = flag;
    tool.on(window, "resize", function () {
        clearTimeout(that.timerOne);
        that.timerOne = setTimeout(function () {
            if (flagToScroll) {
                //分享节点对应大小变化自适应
                let nodeWidth = that.pareNode.parentNode.parentNode.clientWidth;
                that.pointNode.style.width = that.pointNode.querySelectorAll(".item").length * nodeWidth + "px";
                for (let i = 0; i < that.pointNode.querySelectorAll(".item").length; i++) {
                    that.pointNode.querySelectorAll(".item")[i].style.width = nodeWidth - 6 + "px";
                }
                //让父节点右边自适应
                let pointRight = that.pointNode.clientWidth - Math.abs(parseInt(that.pointNode.style.left));
                if (pointRight < that.pareNode.clientWidth) {
                    that.pointNode.style.left = -that.pointNode.clientWidth + that.pareNode.clientWidth + "px";
                }
            } else {
                //让父节点右边自适应
                let pointRight = that.pointNode.clientWidth - Math.abs(parseInt(that.pointNode.style.left));
                if (pointRight < that.pareNode.clientWidth) {
                    that.pointNode.style.left = -that.pointNode.clientWidth + that.pareNode.clientWidth + "px";
                }
            }
        }, 5);
    })
};
//点击按钮滚动
ScrollPhotoComponent.prototype.setRoll = function () {
    let that = this,
        length;
    that.pointLeft.onclick = function () {
        length = parseInt(that.pointNode.style.left) + that.pareNode.clientWidth;
        if (Math.abs(length) >= 0) {
            that.pointNode.style.left = 0 + "px";
            return;
        }
        that.pointNode.style.left = length + "px";
    };
    that.pointRight.onclick = function () {
        length = parseInt(that.pointNode.style.left) - that.pareNode.clientWidth;
        if (Math.abs(length) >= (that.pointNode.clientWidth - that.pareNode.clientWidth)) {
            that.pointNode.style.left = -(that.pointNode.clientWidth - that.pareNode.clientWidth) + "px";
            return;
        }
        that.pointNode.style.left = length + "px";
    };
};
//初始化函数
ScrollPhotoComponent.prototype.init = function (length, data) {
    if (this.pareNode) {
        this.setPlayLeftAndRight();
        this.addAllNode(data);
        this.adjustWidth(length, data);
        this.setRoll();
    }
};

/********************搜索结果个人------个人页面显示*****************/
let personResult_toPerson = function () {
    this.pareNode = document.querySelector(".searchResult-person");
};

/*********************点击选择选项按钮时的页面跳转对象，例如：当天，这个月，这年这些页面跳转时的对象**************/
let SelectKind = function () {
    this.field = null;
    this.nodeList = null;
    this.DropDownButton = null;
};
SelectKind.prototype.setNodeList = function (field, nodeList, DropDownButton) {
    this.field = field;
    this.nodeList = nodeList;
    this.DropDownButton = DropDownButton;
};
//用到基础函数parseURL
SelectKind.prototype.analysisUrl = function () {
    let url = window.location.href,
        parse = parseURL(url),
        urlField = parseURL(url).file,
        urlKind = parse.params.kind;
    if (urlField === this.field) {
        //如果urlKind是存在的
        if (urlKind) {
            for (let i = 0; i < this.nodeList.length; i++) {
                if (this.nodeList[i] === urlKind) {
                    this._setSelectColor(urlKind);
                    return urlKind;
                }
            }
        } else {
            this._setSelectColor(this.nodeList[0]);
            return this.nodeList[0];
        }
    }
};
SelectKind.prototype._setSelectColor = function (urlKind) {
    for (let i = 0; i < this.nodeList.length; i++) {
        if (urlKind === this.nodeList[i]) {
            this.DropDownButton.style.left = i * 82 + "px";
            this.DropDownButton.style.display = "block"
        }
    }
};
SelectKind.prototype.selectByHrefFile = function (pathList, path, length) {
    let word = parseURL(window.location.href).params.word;
    if (word) {
        document.querySelector(".searchInput").value = decodeURI(word);
    }
    for (let i = 0; i < pathList.length; i++) {
        let pareNode = document.getElementById(pathList[i]);
        pareNode.href = getRootPath_web() + "/share/" + pathList[i] + "?word=" + parseURL(window.location.href).params.word;
        if (path === pathList[i]) {
            let node = document.querySelector(".line-select");
            node.style.display = "block";
            node.style.left = length * i + "px";
        }
    }
};
let searchInput = function () {
    this.content = null;
};
searchInput.prototype.getInputContent = function (event) {
    //回车（enter）事件监听
    document.onkeyup = function (e) {
        if (window.event)//如果window.event对象存在，就以此事件对象为准
            e = window.event;
        let code = e.charCode || e.keyCode;
        if (code === 13) {
            //此处编写用户敲回车后的代码
            let content = document.querySelector(".searchInput").value;
            if (content === "") {
                return null;
            } else {
                let path = parseURL(window.location.href).file;
                if (path.indexOf("search") >= 0) {
                    window.open(getRootPath_web() + "/share/" + path + "?word=" + content, "_self");
                } else {
                    window.open(getRootPath_web() + "/share/search" + "?word=" + content, "_self");
                }
            }
        }
    };
    //点击按照内容事件监听
    document.querySelectorAll(".searchFrame-node")[0].onclick = function () {
        let content = document.querySelector(".searchInput").value;
        if (content === "") {
            layer.msg('输入内容为空', {time: 500});
            return null;
        } else {
            window.open(getRootPath_web() + "/share/search_share" + "?word=" + content, "_self");
        }
    };
    document.querySelectorAll(".searchFrame-node")[1].onclick = function () {
        let content = document.querySelector(".searchInput").value;
        if (content === "") {
            layer.msg('输入内容为空', {time: 500});
            return null;
        } else {
            window.open(getRootPath_web() + "/share/search_person" + "?word=" + content, "_self");
        }
    }
};
new searchInput().getInputContent();